//
//  HistoryOrderCell.m
//  ios-supplier
//
//  Created by Benlai on 15/8/3.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "HistoryOrderCell.h"
#import "JFBSubmitOrderDS.h"
#import "JFBOrderProductDS.h"


@interface HistoryOrderCell ()

//图片1
@property (weak, nonatomic) IBOutlet UIImageView *image1;
//图片2
@property (weak, nonatomic) IBOutlet UIImageView *image2;
//图片3
@property (weak, nonatomic) IBOutlet UIImageView *image3;
//图片4
@property (weak, nonatomic) IBOutlet UIImageView *image4;
//订单状态
@property (weak, nonatomic) IBOutlet UILabel *StatusLabel;
//价格
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel;
//时间
@property (weak, nonatomic) IBOutlet UILabel *TimeLabel;
//件数
@property (weak, nonatomic) IBOutlet UILabel *PieceLabel;



@end
@implementation HistoryOrderCell


- (void)setHistoryDS:(JFBSubmitOrderDS *)historyDS
{
    _historyDS = historyDS;


    
    switch (historyDS.purchaseStatus)
    {
   
        case 1:
            _StatusLabel.text = @"待审核";
            _StatusLabel.textColor = TextColorDefault;
            break;
        case 2:
            _StatusLabel.text = @"待发货";
            _StatusLabel.textColor = TextColorDefault;
            break;
        case 3:
            _StatusLabel.text = @"已拒绝";
            _StatusLabel.textColor = TextColorImportant;
            break;
        case 4:
            _StatusLabel.text = @"已发货";
            _StatusLabel.textColor = TextColorDefault;
            break;
        case 5:
            _StatusLabel.text = @"已收货";
            _StatusLabel.textColor = TextColorDefault;
            break;
        default:
            break;
    }
    
    self.TimeLabel.text = historyDS.createTime;
    self.TimeLabel.textColor = [UIColor colorFromHexValue:0x232323];
    
    self.image1 = [self setImageBorder:self.image1 BorderWithWidth:1];
    self.image2 = [self setImageBorder:self.image2 BorderWithWidth:1];
    self.image3 = [self setImageBorder:self.image3 BorderWithWidth:1];
    self.image4 = [self setImageBorder:self.image4 BorderWithWidth:1];
    
    self.PriceLabel.text = [NSString stringWithFormat:@"￥%.2f", [_historyDS.purchasePrice floatValue]];
    
//    NSInteger count = 0;
//    
//    for (JFBSubmitOrderDS *goodsInfo in self.historyDS.shopSOItem)
//    {
//        count += goodsInfo.purchaseUnits;
//        
//    }
   
    self.PieceLabel.text = [NSString stringWithFormat:@"共%ld件",(long)_historyDS.purchaseUnits];
    self.PieceLabel.textColor = [UIColor colorFromHexValue:0x232323];
    
    if (historyDS.shopSOItem.count < 1)
    {
        self.image4.hidden = YES;
    }
    if (historyDS.shopSOItem.count >= 1)
    {
        [self picture:self.image1 index:0 withOpen:!(historyDS.shopSOItem.count >= 1) ];
        self.image4.hidden = YES;
    }
    else
    {
        self.image1.hidden = YES;
    }
    if (historyDS.shopSOItem.count >= 2)
    {
        [self picture:self.image2 index:1 withOpen:!(historyDS.shopSOItem.count >= 2)];
        self.image4.hidden = YES;
    }
    else
    {
        self.image2.hidden = YES;
    }
    if (historyDS.shopSOItem.count >= 3)
    {
        [self picture:self.image3 index:2 withOpen:!(historyDS.shopSOItem.count >= 3)];
        self.image4.hidden = NO;
    }
    else
    {
        self.image3.hidden = YES;
    }
}


//自定义cell间距
- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 10;
    frame.size.height -= 10;
    [super setFrame:frame];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(UIImageView *)setImageBorder:(UIImageView *)imageView BorderWithWidth:(CGFloat)border
{
    [imageView.layer setBorderWidth:border];
    [imageView.layer setBorderColor:[UIColor colorFromHexValue:0xeeeeee].CGColor];
    return imageView;
}

-(void)picture:(UIImageView *)imageView index:(NSInteger) index withOpen:(BOOL)isOpen
{
    imageView.hidden = isOpen;
    JFBOrderProductDS *product = _historyDS.shopSOItem[index];

    [imageView sd_setImageWithURL:[NSURL URLWithString:product.photoUrl] placeholderImage:[UIImage imageNamed:ImageDefaultPlaceholder]];
}



@end
